package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.BScoresDiscountService;
import cn.huiyunche.base.service.mappers.BScoresDiscountMapper;
import cn.huiyunche.base.service.model.BScoresDiscount;
import cn.huiyunche.base.service.model.BScoresDiscountExample;
import cn.huiyunche.tools.basic.exceptions.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 积分活动接口实现类
 *
 * @author lm
 */
@Service
public class bScoresDiscountServiceImpl implements BScoresDiscountService {

    private static final Logger LOGGER = LoggerFactory.getLogger(bScoresDiscountServiceImpl.class);

    @Autowired
    private BScoresDiscountMapper bScoresDiscountMapper = null;

    private BScoresDiscountMapper getBScoresDiscountMapper() {
        return this.bScoresDiscountMapper;
    }

    /**
     * 根据用户类型 查询积分活动
     *
     * @param userType
     * @return
     */
    @Override
    public List<BScoresDiscount> selectByUserType(int userType, int type) {
        LOGGER.info("select scores list discount by userType params userType : {}, {}", userType, type);
        try {
            BScoresDiscountExample example = new BScoresDiscountExample();
            example.createCriteria().andUserTypeEqualTo(userType).andIsEnableEqualTo(true).andTypeEqualTo(type).
                    andBeginDateLessThanOrEqualTo(new Date()).andEndDateGreaterThanOrEqualTo(new Date());
            return this.getBScoresDiscountMapper().selectByExample(example);
        } catch (Exception e) {
            LOGGER.error("select scores list discount by userType params userType : {}, error : {}.", userType, e);
            throw new BusinessException("根据用户类型查询积分活动异常");
        }
    }

}
